
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>魔符(Sigil) · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="documentation.html" />
    
    
    <link rel="prev" href="mix.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">第一部分：基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="basics.html">
            
                <a href="basics.html">
            
                    
                    基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="collections.html">
            
                <a href="collections.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="enum.html">
            
                <a href="enum.html">
            
                    
                    Enum 模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="pattern-matching.html">
            
                <a href="pattern-matching.html">
            
                    
                    模式匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="control-structures.html">
            
                <a href="control-structures.html">
            
                    
                    控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="functions.html">
            
                <a href="functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="pipe-operator.html">
            
                <a href="pipe-operator.html">
            
                    
                    管道操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="modules.html">
            
                <a href="modules.html">
            
                    
                    模块(Module)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="mix.html">
            
                <a href="mix.html">
            
                    
                    Mix
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.11" data-path="sigils.html">
            
                <a href="sigils.html">
            
                    
                    魔符(Sigil)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="documentation.html">
            
                <a href="documentation.html">
            
                    
                    文档模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="testing.html">
            
                <a href="testing.html">
            
                    
                    测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="comprehensions.html">
            
                <a href="comprehensions.html">
            
                    
                    推导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="strings.html">
            
                <a href="strings.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="date-time.html">
            
                <a href="date-time.html">
            
                    
                    日期和时间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="mix-tasks.html">
            
                <a href="mix-tasks.html">
            
                    
                    自定义Mix任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="iex-helpers.html">
            
                <a href="iex-helpers.html">
            
                    
                    IEx辅助函数
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二部分：高级</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../advanced/erlang.html">
            
                <a href="../advanced/erlang.html">
            
                    
                    和Erlang互操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../advanced/error-handling.html">
            
                <a href="../advanced/error-handling.html">
            
                    
                    错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../advanced/escripts.html">
            
                <a href="../advanced/escripts.html">
            
                    
                    可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../advanced/concurrency.html">
            
                <a href="../advanced/concurrency.html">
            
                    
                    并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../advanced/otp-concurrency.html">
            
                <a href="../advanced/otp-concurrency.html">
            
                    
                    OTP并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../advanced/otp-supervisors.html">
            
                <a href="../advanced/otp-supervisors.html">
            
                    
                    OTP Supervisors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../advanced/otp-distribution.html">
            
                <a href="../advanced/otp-distribution.html">
            
                    
                    OTP 分布式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../advanced/metaprogramming.html">
            
                <a href="../advanced/metaprogramming.html">
            
                    
                    元编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="../advanced/umbrella-projects.html">
            
                <a href="../advanced/umbrella-projects.html">
            
                    
                    Umbrella Projects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="../advanced/typespec.html">
            
                <a href="../advanced/typespec.html">
            
                    
                    Specifications and types
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="../advanced/behaviours.html">
            
                <a href="../advanced/behaviours.html">
            
                    
                    行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="../advanced/gen-stage.html">
            
                <a href="../advanced/gen-stage.html">
            
                    
                    GenStage
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="../advanced/protocols.html">
            
                <a href="../advanced/protocols.html">
            
                    
                    协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="../advanced/nerves.html">
            
                <a href="../advanced/nerves.html">
            
                    
                    Nerves
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第三部分：ECTO</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../ecto/basics.html">
            
                <a href="../ecto/basics.html">
            
                    
                    Basics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../ecto/changesets.html">
            
                <a href="../ecto/changesets.html">
            
                    
                    Changesets
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../ecto/associations.html">
            
                <a href="../ecto/associations.html">
            
                    
                    关联关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../ecto/querying.html">
            
                <a href="../ecto/querying.html">
            
                    
                    查询
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第四部分：专题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../specifics/plug.html">
            
                <a href="../specifics/plug.html">
            
                    
                    Plug
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../specifics/eex.html">
            
                <a href="../specifics/eex.html">
            
                    
                    嵌入的 Elixir(EEx)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../specifics/ets.html">
            
                <a href="../specifics/ets.html">
            
                    
                    Erlang 项式存储(ETS)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../specifics/mnesia.html">
            
                <a href="../specifics/mnesia.html">
            
                    
                    Mnesia 数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../specifics/debugging.html">
            
                <a href="../specifics/debugging.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第五部分：程序库</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../libraries/guardian.html">
            
                <a href="../libraries/guardian.html">
            
                    
                    Guardian(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../libraries/poolboy.html">
            
                <a href="../libraries/poolboy.html">
            
                    
                    Poolboy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../libraries/benchee.html">
            
                <a href="../libraries/benchee.html">
            
                    
                    Benchee
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../libraries/bypass.html">
            
                <a href="../libraries/bypass.html">
            
                    
                    Bypass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../libraries/distillery.html">
            
                <a href="../libraries/distillery.html">
            
                    
                    Distillery(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../libraries/stream-data.html">
            
                <a href="../libraries/stream-data.html">
            
                    
                    StreamData
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >魔符(Sigil)</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x4F7F;&#x7528;&#x548C;&#x5B9A;&#x4E49;&#x9B54;&#x7B26;&#x3002;</p>
<h2 id="&#x9B54;&#x7B26;sigil-&#x6982;&#x8FF0;">&#x9B54;&#x7B26;(Sigil) &#x6982;&#x8FF0;</h2>
<p>Elixir&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x53EB;&#x505A;&#x9B54;&#x7B26;(Sigil)&#x7684;&#x8BED;&#x6CD5;&#x7CD6;&#x6765;&#x8868;&#x793A;&#x548C;&#x5904;&#x7406;&#x5B57;&#x9762;&#x91CF;&#x3002;&#x4E00;&#x4E2A;&#x9B54;&#x7B26;&#x4EE5;<code>~</code>&#x5F00;&#x5934;&#x7136;&#x540E;&#x63A5;&#x4E0A;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x3002;Elixir&#x5DF2;&#x7ECF;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E9B;&#x5185;&#x7F6E;&#x7684;&#x9B54;&#x7B26;&#x3002;&#x5F53;&#x7136;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x6709;&#x9700;&#x8981;&#x7684;&#x8BDD;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x521B;&#x9020;&#x81EA;&#x5DF1;&#x7684;&#x9B54;&#x7B26;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E9B;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x7684;&#x9B54;&#x7B26;(&#x5BF9;&#x7740;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x770B;&#x66F4;&#x597D;):</p>
<ul>
<li><code>~C</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;<strong>&#x4E0D;&#x5904;&#x7406;</strong>&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x7684;&#x5B57;&#x7B26;&#x5217;&#x8868;</li>
<li><code>~c</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;<strong>&#x5904;&#x7406;</strong>&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x7684;&#x5B57;&#x7B26;&#x5217;&#x8868;</li>
<li><code>~R</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;<strong>&#x4E0D;&#x5904;&#x7406;</strong>&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x7684;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;</li>
<li><code>~r</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;<strong>&#x5904;&#x7406;</strong>&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x7684;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;</li>
<li><code>~S</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;<strong>&#x4E0D;&#x5904;&#x7406;</strong>&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x7684;&#x5B57;&#x7B26;&#x4E32;</li>
<li><code>~s</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;<strong>&#x5904;&#x7406;</strong>&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x7684;&#x5B57;&#x7B26;&#x4E32;</li>
<li><code>~W</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;<strong>&#x4E0D;&#x5904;&#x7406;</strong>&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x7684;&#x5355;&#x8BCD;&#x5217;&#x8868;</li>
<li><code>~w</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;<strong>&#x5904;&#x7406;</strong>&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x7684;&#x5355;&#x8BCD;&#x5217;&#x8868;</li>
<li><code>~N</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A; <code>NaiveDateTime</code> &#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;</li>
</ul>
<p>&#x53EF;&#x7528;&#x7684;&#x5206;&#x9694;&#x7B26;&#x5982;&#x4E0B;:</p>
<ul>
<li><code>&lt;...&gt;</code> &#x5C16;&#x62EC;&#x53F7;</li>
<li><code>{...}</code> &#x5927;&#x62EC;&#x53F7;</li>
<li><code>[...]</code> &#x4E2D;&#x62EC;&#x53F7;</li>
<li><code>(...)</code> &#x5C0F;&#x62EC;&#x53F7;</li>
<li><code>|...|</code> &#x4E24;&#x6761;&#x76F4;&#x7EBF;(&#x53CD;&#x659C;&#x6760;&#x4E0A;&#x9762;&#x90A3;&#x4E2A;)</li>
<li><code>/.../</code> &#x659C;&#x6760;</li>
<li><code>&quot;...&quot;</code> &#x53CC;&#x5F15;&#x53F7;</li>
<li><code>&apos;...&apos;</code> &#x5355;&#x5F15;&#x53F7;</li>
</ul>
<h3 id="&#x5B57;&#x7B26;&#x5217;&#x8868;">&#x5B57;&#x7B26;&#x5217;&#x8868;</h3>
<p> <code>~c</code> &#x548C; <code>~C</code> &#x4F1A;&#x5206;&#x522B;&#x521B;&#x5EFA;&#x4E0D;&#x540C;&#x7684;&#x5B57;&#x7B26;&#x5217;&#x8868;. &#x6BD4;&#x5982;:</p>
<pre><code class="lang-elixir">iex&gt; ~c/<span class="hljs-number">2</span> + <span class="hljs-number">7</span> = <span class="hljs-comment">#{2 + 7}/</span>
<span class="hljs-string">&apos;2 + 7 = 9&apos;</span>

iex&gt; ~C/<span class="hljs-number">2</span> + <span class="hljs-number">7</span> = <span class="hljs-comment">#{2 + 7}/</span>
<span class="hljs-string">&apos;2 + 7 = \#{2 + 7}&apos;</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;<code>~c</code>&#x5C0F;&#x5199;c&#x5BF9;&#x5E94;&#x7684;&#x9B54;&#x7B26;&#x5904;&#x7406;&#x4E86;&#x5B57;&#x7B26;&#x5217;&#x8868;&#x4E2D;&#x7684;&#x63D2;&#x5165;&#x503C;&#xFF0C;&#x7136;&#x800C;<code>~C</code>&#x5927;&#x5199;C&#x5BF9;&#x5E94;&#x7684;&#x9B54;&#x7B26;&#x6CA1;&#x6709;&#x5904;&#x7406;&#x3002;&#x5728;&#x5185;&#x7F6E;&#x7684;&#x9B54;&#x7B26;&#x4E2D;&#xFF0C;&#x8FD9;&#x79CD;&#x5927;&#x5C0F;&#x5199;&#x4EE3;&#x8868;&#x76F8;&#x53CD;&#x7684;&#x573A;&#x666F;&#x7684;&#x4F8B;&#x5B50;&#x5F88;&#x5E38;&#x89C1;&#x3002;</p>
<h3 id="&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;">&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;</h3>
<p> <code>~r</code> &#x548C; <code>~R</code>&#x8FD9;&#x4E24;&#x4E2A;&#x9B54;&#x7B26;&#x7528;&#x6765;&#x8868;&#x793A;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x3002;&#x53EF;&#x4EE5;&#x7528;&#x8FD9;&#x4E24;&#x4E2A;&#x9B54;&#x7B26;&#x6765;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x6216;&#x8005;&#x901A;&#x8FC7;<code>Regex</code>&#x51FD;&#x6570;&#x6765;&#x4F7F;&#x7528;&#x5B83;&#x4EEC;&#x3002;&#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;:</p>
<pre><code class="lang-elixir">iex&gt; re = ~r/elixir/
~r/elixir/

iex&gt; <span class="hljs-string">&quot;Elixir&quot;</span> =~ re
<span class="hljs-keyword">false</span>

iex&gt; <span class="hljs-string">&quot;elixir&quot;</span> =~ re
<span class="hljs-keyword">true</span>
</code></pre>
<p>&#x5728;&#x7B2C;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&quot;Elixir&quot;&#x5E76;&#x4E0D;&#x4E0E;<code>re</code>&#x7684;&#x503C;&#x76F8;&#x7B49;&#x3002; &#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x662F;&#x5927;&#x5C0F;&#x5199;&#x654F;&#x611F;&#x7684;&#x3002;&#x7531;&#x4E8E;Elixir&#x652F;&#x6301; Perl Compatible Regular Expressions (PCRE), &#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x5728;&#x9B54;&#x7B26;&#x7684;&#x672B;&#x5C3E;&#x52A0;<code>i</code>&#x6765;&#x5173;&#x95ED;&#x5927;&#x5C0F;&#x5199;&#x654F;&#x611F;&#x3002;</p>
<pre><code class="lang-elixir">iex&gt; re = ~r/elixir/i
~r/elixir/i

iex&gt; <span class="hljs-string">&quot;Elixir&quot;</span> =~ re
<span class="hljs-keyword">true</span>

iex&gt; <span class="hljs-string">&quot;elixir&quot;</span> =~ re
<span class="hljs-keyword">true</span>
</code></pre>
<p>&#x9664;&#x6B64;&#x4E4B;&#x5916;, Elixir&#x8FD8;&#x63D0;&#x4F9B;&#x57FA;&#x4E8E;Erlang&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x5E93;&#x7684; <a href="https://hexdocs.pm/elixir/Regex.html" target="_blank">Regex</a> API&#x3002; &#x8BA9;&#x6211;&#x4EEC;&#x7528;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x9B54;&#x7B26;&#x6765;&#x5B9E;&#x73B0;<code>Regex.split/2</code> :</p>
<pre><code class="lang-elixir">iex&gt; string = <span class="hljs-string">&quot;100_000_000&quot;</span>
<span class="hljs-string">&quot;100_000_000&quot;</span>

iex&gt; Regex.split(~r/<span class="hljs-number">_</span>/, string)
[<span class="hljs-string">&quot;100&quot;</span>, <span class="hljs-string">&quot;000&quot;</span>, <span class="hljs-string">&quot;000&quot;</span>]
</code></pre>
<p>&#x5982;&#x4E0A;&#x6240;&#x793A;, &#x5B57;&#x7B26;&#x4E32; <code>&quot;100_000_000&quot;</code> &#x6839;&#x636E;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;<code>~r/_/</code> (&#x4EE3;&#x8868;&#x5339;&#x914D;&#x4E0B;&#x5212;&#x7EBF;)&#x88AB;&#x5207;&#x5206;&#x4E86;&#x3002;&#x51FD;&#x6570; <code>Regex.split</code> &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x3002;</p>
<h3 id="&#x5B57;&#x7B26;&#x4E32;">&#x5B57;&#x7B26;&#x4E32;</h3>
<p> <code>~s</code> &#x548C; <code>~S</code> &#x8FD9;&#x4E24;&#x4E2A;&#x9B54;&#x7B26;&#x7528;&#x6765;&#x521B;&#x5EFA;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;:</p>
<pre><code class="lang-elixir">iex&gt; ~s/the cat <span class="hljs-keyword">in</span> the hat on the mat/
<span class="hljs-string">&quot;the cat in the hat on the mat&quot;</span>

iex&gt; ~S/the cat <span class="hljs-keyword">in</span> the hat on the mat/
<span class="hljs-string">&quot;the cat in the hat on the mat&quot;</span>
</code></pre>
<p>&#x8FD9;&#x4E24;&#x4E2A;&#x9B54;&#x7B26;&#x521B;&#x5EFA;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x6709;&#x4E0D;&#x540C;&#x5417;? &#x5B83;&#x4EEC;&#x7684;&#x4E0D;&#x540C;&#x548C;&#x524D;&#x9762;&#x63D0;&#x5230;&#x7684;&#x521B;&#x5EFA;&#x5B57;&#x7B26;&#x5217;&#x8868;&#x7684;&#x4E24;&#x4E2A;&#x9B54;&#x7B26;&#x7684;&#x4E0D;&#x540C;&#x5F88;&#x50CF;&#x3002; &#x7B54;&#x6848;&#x5C31;&#x662F;&#x662F;&#x5426;&#x5904;&#x7406;&#x63D2;&#x503C;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x3002; &#x4E3E;&#x4E2A;&#x66F4;&#x660E;&#x663E;&#x7684;&#x4F8B;&#x5B50;:</p>
<pre><code class="lang-elixir">iex&gt; ~s/welcome to elixir <span class="hljs-comment">#{String.downcase &quot;SCHOOL&quot;}/</span>
<span class="hljs-string">&quot;welcome to elixir school&quot;</span>

iex&gt; ~S/welcome to elixir <span class="hljs-comment">#{String.downcase &quot;SCHOOL&quot;}/</span>
<span class="hljs-string">&quot;welcome to elixir \#{String.downcase \&quot;SCHOOL\&quot;}&quot;</span>
</code></pre>
<h3 id="&#x5355;&#x8BCD;&#x5217;&#x8868;">&#x5355;&#x8BCD;&#x5217;&#x8868;</h3>
<p>&#x8FD9;&#x4E2A;&#x9B54;&#x7B26;&#x53EF;&#x4EE5;&#x5728;&#x5904;&#x7406;&#x8868;&#x793A;&#x53E5;&#x5B50;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x65F6;&#x5019;&#x7701;&#x4E0B;&#x5F88;&#x591A;&#x7CBE;&#x529B;&#x3002; &#x5B83;&#x53EF;&#x4EE5;&#x964D;&#x4F4E;&#x4EE3;&#x7801;&#x590D;&#x6742;&#x5EA6;&#x3001;&#x8282;&#x7701;&#x65F6;&#x95F4;&#x3001;&#x6309;&#x952E;&#x6B21;&#x6570;&#x3002;&#x56E0;&#x4E3A;&#x5B83;&#x80FD;&#x591F;&#x5C06;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x81EA;&#x52A8;&#x5206;&#x5272;&#x5E76;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x3002;&#x4E3E;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50; :</p>
<pre><code class="lang-elixir">iex&gt; ~w/i love elixir school/
[<span class="hljs-string">&quot;i&quot;</span>, <span class="hljs-string">&quot;love&quot;</span>, <span class="hljs-string">&quot;elixir&quot;</span>, <span class="hljs-string">&quot;school&quot;</span>]

iex&gt; ~W/i love elixir school/
[<span class="hljs-string">&quot;i&quot;</span>, <span class="hljs-string">&quot;love&quot;</span>, <span class="hljs-string">&quot;elixir&quot;</span>, <span class="hljs-string">&quot;school&quot;</span>]
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x5206;&#x9694;&#x7B26;&#x5185;&#x7684;&#x8F93;&#x5165;&#x90FD;&#x88AB;&#x6309;&#x7A7A;&#x683C;&#x5206;&#x5272;&#x5E76;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x3002;&#x4F46;&#x662F;&#x4E24;&#x4E2A;&#x9B54;&#x7B26;&#x7684;&#x7ED3;&#x679C;&#x4F3C;&#x4E4E;&#x6CA1;&#x4EC0;&#x4E48;&#x533A;&#x522B;&#x3002;&#x533A;&#x522B;&#x8FD8;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x8FD8;&#x662F;&#x662F;&#x5426;&#x5904;&#x7406;&#x63D2;&#x503C;&#x4E0E;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x3002;&#x518D;&#x770B;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;:</p>
<pre><code class="lang-elixir">iex&gt; ~w/i love <span class="hljs-comment">#{&apos;e&apos;}lixir school/</span>
[<span class="hljs-string">&quot;i&quot;</span>, <span class="hljs-string">&quot;love&quot;</span>, <span class="hljs-string">&quot;elixir&quot;</span>, <span class="hljs-string">&quot;school&quot;</span>]

iex&gt; ~W/i love <span class="hljs-comment">#{&apos;e&apos;}lixir school/</span>
[<span class="hljs-string">&quot;i&quot;</span>, <span class="hljs-string">&quot;love&quot;</span>, <span class="hljs-string">&quot;\#{&apos;e&apos;}lixir&quot;</span>, <span class="hljs-string">&quot;school&quot;</span>]
</code></pre>
<h3 id="&#x771F;&#xB7;&#x65F6;&#x95F4;&#x65E5;&#x671F;">&#x771F;&#xB7;&#x65F6;&#x95F4;&#x65E5;&#x671F;</h3>
<p>&#x5F53;&#x9700;&#x8981;&#x521B;&#x5EFA;<strong>&#x4E0D;&#x5E26;</strong>&#x65F6;&#x533A;&#x7684;&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x65F6;&#xFF0C;&#x9B54;&#x7B26; <a href="https://hexdocs.pm/elixir/NaiveDateTime.html" target="_blank">&#x771F;&#xB7;&#x65F6;&#x95F4;&#x65E5;&#x671F;</a> &#x5C06;&#x5F88;&#x6709;&#x7528;&#x3002; </p>
<p>&#x5728;&#x5927;&#x90E8;&#x5206;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5E94;&#x8BE5;&#x907F;&#x514D;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x9B54;&#x7B26;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x8FD9;&#x4E2A;&#x9B54;&#x7B26;&#x5728;&#x6A21;&#x5F0F;&#x5339;&#x914D;&#x7684;&#x65F6;&#x5019;&#x5F88;&#x6709;&#x7528;&#x3002; &#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;:</p>
<pre><code class="lang-elixir">iex&gt; NaiveDateTime.from_iso8601(<span class="hljs-string">&quot;2015-01-23 23:50:07&quot;</span>) == {<span class="hljs-symbol">:ok</span>, ~N[<span class="hljs-number">2015</span>-<span class="hljs-number">01</span>-<span class="hljs-number">23</span> <span class="hljs-number">23</span><span class="hljs-symbol">:</span><span class="hljs-number">50</span><span class="hljs-symbol">:</span><span class="hljs-number">07</span>]}
</code></pre>
<h2 id="&#x5B9A;&#x4E49;&#x4F60;&#x81EA;&#x5DF1;&#x7684;&#x9B54;&#x7B26;">&#x5B9A;&#x4E49;&#x4F60;&#x81EA;&#x5DF1;&#x7684;&#x9B54;&#x7B26;</h2>
<p>Elixir&#x8FD9;&#x95E8;&#x8BED;&#x8A00;&#x6709;&#x4E00;&#x4E2A;&#x76EE;&#x7684;&#x5C31;&#x662F;&#x8BA9;Elixir&#x6210;&#x4E3A;&#x4E00;&#x95E8;&#x53EF;&#x6269;&#x5C55;&#x7684;&#x8BED;&#x8A00;&#x3002;&#x56E0;&#x6B64;&#x4F60;&#x80FD;&#x591F;&#x5B9A;&#x4E49;&#x6216;&#x8005;&#x662F;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;&#x9B54;&#x7B26;&#x5E76;&#x4E0D;&#x662F;&#x4EC0;&#x4E48;&#x5947;&#x602A;&#x7684;&#x4E8B;&#x60C5;&#x3002; &#x5728;&#x4E0B;&#x9762;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x9B54;&#x7B26;&#xFF0C;&#x5B83;&#x80FD;&#x591F;&#x5C06;&#x5C0F;&#x5199;&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x5316;&#x4E3A;&#x5927;&#x5199;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x5C3D;&#x7BA1;&#x5DF2;&#x7ECF;&#x6709;&#x4E00;&#x4E2A;&#x51FD;&#x6570; (<code>String.upcase/1</code>)&#x5B9E;&#x73B0;&#x4E86;&#x8FD9;&#x4E2A;&#x529F;&#x80FD;&#xFF0C;&#x6211;&#x4EEC;&#x4ECD;&#x5C06;&#x5BF9;&#x90A3;&#x4E2A;&#x51FD;&#x6570;&#x8FDB;&#x884C;&#x5305;&#x88C5;&#xFF0C;&#x8BA9;&#x5B83;&#x53D8;&#x6210;&#x4E00;&#x4E2A;&#x8BED;&#x6CD5;&#x7CD6;&#x3002;</p>
<pre><code class="lang-elixir">
iex&gt; <span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">MySigils</span></span> <span class="hljs-keyword">do</span>
...&gt;   <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sigil_u</span></span>(string, []), <span class="hljs-symbol">do:</span> String.upcase(string)
...&gt; <span class="hljs-keyword">end</span>

iex&gt; import MySigils
<span class="hljs-keyword">nil</span>

iex&gt; ~u/elixir school/
ELIXIR SCHOOL
</code></pre>
<p>&#x9996;&#x5148;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x6A21;&#x5757; <code>MySigils</code> &#xFF0C;&#x7136;&#x540E;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x51FD;&#x6570; <code>sigil_u</code>&#x3002;&#x56E0;&#x4E3A;&#x6CA1;&#x6709;&#x4E00;&#x4E2A;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x9B54;&#x7B26;&#x662F;<code>~u</code>&#x8FD9;&#x4E2A;&#x683C;&#x5F0F;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x4E2A;&#x9B54;&#x7B26;&#x7684;&#x5F62;&#x5F0F;&#x5C31;&#x662F;&#x5B83;&#x3002;&#x51FD;&#x6570;&#x540D;&#x540E;&#x9762;&#x7684;<code>_u</code>&#x8868;&#x793A;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x7528;<code>u</code>&#x4F5C;&#x4E3A;&#x8FD9;&#x4E2A;&#x9B54;&#x7B26;&#x7684;&#x6807;&#x8BC6;&#x3002;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x63A5;&#x53D7;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E00;&#x4E2A;&#x8F93;&#x5165;&#x548C;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="mix.html" class="navigation navigation-prev " aria-label="Previous page: Mix">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="documentation.html" class="navigation navigation-next " aria-label="Next page: 文档模块">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"version":"1.0.2","title":"魔符(Sigil)","level":"1.11","depth":1,"next":{"title":"文档模块","level":"1.12","depth":1,"path":"lessons/basics/documentation.md","ref":"lessons/basics/documentation.md","articles":[]},"previous":{"title":"Mix","level":"1.10","depth":1,"path":"lessons/basics/mix.md","ref":"lessons/basics/mix.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"lessons/basics/sigils.md","mtime":"2019-11-05T02:25:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-11-05T03:01:22.004Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

